import { getRecoil } from 'recoil-nexus';

interface IUserAtom {
  id?: string;
  username?: string;
  firstName?: string;
  lastName?: string;
  email?: string;
  emailVerified?: boolean;
  token: string;
}

const userAtom = atom<IUserAtom>({
  key: 'userAtom',
  default: {} as IUserAtom
});

export const getRecoilOfUser = () => getRecoil(userAtom);

export const useUser = () => {
  const [userInfo, setUserInfo] = useRecoilState(userAtom);

  return {
    userInfo,
    setUserInfo
  };
};
